package com.hspedu.newData.面试题;

import org.junit.Test;

/**
 * @Author: yh
 * @description: 
 * @CreateTime: 2025-05-20 
 * @Version: 1.0
 */

public class 面试题1617连续数列 {

    public int maxSubArray(int[] nums) {

        int[] dp = new int[nums.length];

        dp[0] = nums[0];
        int max = nums[0];
        for (int i = 1; i < nums.length; i++) {
            dp[i] = Math.max(dp[i-1]+nums[i],nums[i]);
            max = Math.max(dp[i],max);
        }

        return max;
    }

    @Test
    public void test() {
        // 测试代码

//        maxSubArray(new int[]{-2,1,-3,4,-1,2,1,-5,4});
        maxSubArray(new int[]{-10,1,3,-4,2,3,3,4,1,3,-2,1,-3,4,-1,2,1,-5,4});
    }
}
